<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>发布帖子 - 论坛系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: #f8f9fa;
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }

        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            text-align: center;
        }

        .header h2 {
            font-size: 28px;
            font-weight: 600;
            margin-bottom: 10px;
        }

        .header p {
            opacity: 0.9;
            font-size: 16px;
        }

        .form-container {
            padding: 40px;
        }

        .form-group {
            margin-bottom: 25px;
        }

        .form-group label {
            display: block;
            margin-bottom: 10px;
            color: #333;
            font-weight: 600;
            font-size: 16px;
        }

        .form-group input,
        .form-group textarea {
            width: 100%;
            padding: 15px;
            border: 2px solid #e1e5e9;
            border-radius: 10px;
            font-size: 16px;
            font-family: inherit;
            transition: border-color 0.3s ease, box-shadow 0.3s ease;
        }

        .form-group input:focus,
        .form-group textarea:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }

        .form-group textarea {
            min-height: 200px;
            resize: vertical;
        }

        .submit-btn {
            width: 100%;
            padding: 15px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 18px;
            font-weight: 600;
            cursor: pointer;
            transition: transform 0.2s ease, box-shadow 0.3s ease;
        }

        .submit-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
        }

        .message {
            padding: 15px;
            border-radius: 10px;
            margin-bottom: 20px;
            font-size: 14px;
            text-align: center;
        }

        .message.error {
            background-color: #fee;
            color: #c33;
            border: 1px solid #fcc;
        }

        .message.success {
            background-color: #efe;
            color: #363;
            border: 1px solid #cfc;
        }

        .back-link {
            display: inline-block;
            margin-top: 20px;
            color: #667eea;
            text-decoration: none;
            font-weight: 500;
            transition: color 0.3s ease;
        }

        .back-link:hover {
            color: #764ba2;
            text-decoration: underline;
        }

        .back-link::before {
            content: '← ';
            margin-right: 5px;
        }

        .char-counter {
            text-align: right;
            color: #666;
            font-size: 14px;
            margin-top: 5px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <h2>发布新帖子</h2>
        <p>分享您的想法和见解</p>
    </div>

    <div class="form-container">
        <% String msg = (String) request.getAttribute("msg"); %>
        <% if (msg != null && !msg.isEmpty()) { %>
        <div class="message error"><%= msg %></div>
        <% } %>

        <form action="/post/save" method="post">
            <div class="form-group">
                <label for="title">帖子标题</label>
                <input type="text" id="title" name="title" required placeholder="请输入一个吸引人的标题..." maxlength="100">
                <div class="char-counter">
                    <span id="title-count">0</span>/100
                </div>
            </div>

            <div class="form-group">
                <label for="content">帖子内容</label>
                <textarea id="content" name="content" required placeholder="请详细描述您的内容..."></textarea>
                <div class="char-counter">
                    <span id="content-count">0</span> 字符
                </div>
            </div>

            <button type="submit" class="submit-btn">发布帖子</button>
        </form>

        <a href="/main" class="back-link">返回首页</a>
    </div>
</div>

<script>
    // 字符计数功能
    const titleInput = document.getElementById('title');
    const contentTextarea = document.getElementById('content');
    const titleCount = document.getElementById('title-count');
    const contentCount = document.getElementById('content-count');

    titleInput.addEventListener('input', function() {
        titleCount.textContent = this.value.length;
    });

    contentTextarea.addEventListener('input', function() {
        contentCount.textContent = this.value.length;
    });

    // 表单验证
    document.querySelector('form').addEventListener('submit', function(e) {
        const title = titleInput.value.trim();
        const content = contentTextarea.value.trim();

        if (title.length < 2) {
            e.preventDefault();
            alert('标题至少需要2个字符');
            titleInput.focus();
            return;
        }

        if (content.length < 2) {
            e.preventDefault();
            alert('内容至少需要2个字符');
            contentTextarea.focus();
            return;
        }
    });
</script>
</body>
</html>
